layui.use(['table', 'admin', 'ax','laydate'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var laydate = layui.laydate;

    laydate.render({
    	elem:'#startSingleTime'
    });
    
    laydate.render({
    	elem:'#endSinglePutTime'
    });

    laydate.render({
    	elem:'#startTime'
    });
    
    laydate.render({
    	elem:'#endTime'
    });

    /**
     * 拣货单明细表管理
     */
    var StorageOutDetailed = {
        tableId: "storageOutDetailedTable"
    };

    /**
     * 初始化表格的列
     */
    StorageOutDetailed.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: 'ID'},
            {field: 'storageOutStatus', sort: true, title: 'Picking Status',templet: '#storageOutStatusTpl'},
            {field: 'stockId', sort: true, title: 'Inventory ID', style:'font-weight: 600;', hide: true},
            {field: 'storageOutName', sort: true, title: 'Picking Person', style:'background-color: #ecf5ff;font-weight: 600;'},
            {field: 'updateTime', sort: true, title: 'Picking Time', style:'background-color: #ecf5ff;font-weight: 600;'},
            {field: 'storageOutNumber', sort: true, title: 'Picking Order No', style:'background-color: #ecf5ff;font-weight: 600;',width:140},
            {field: 'storagePostionNumber', sort: true, title: 'Location', style:'background-color: #ecf5ff;font-weight: 600;'},
            {field: 'trayNumber', sort: true, title: 'Tray No', style:'background-color: #ecf5ff;font-weight: 600;'},
            {field: 'storageGoodsname', sort: true, title: 'Product', style:'background-color: #dbf1e1;font-weight: 600;',width:260},
            {field: 'storageGoodscode', sort: true, title: 'Code', style:'background-color: #dbf1e1;font-weight: 600;'},
            {field: 'goodsNo', sort: true, title: 'Item No', style:'background-color: #dbf1e1;font-weight: 600;', totalRowText: 'Total:'},
            {field: 'storageNumber', sort: true, title: 'Planned Qty', style:'background-color: #dbf1e1;font-weight: 600;', totalRow: true},
            {field: 'realNum', sort: true, title: 'Actual Qty', style:'background-color: #dbf1e1;font-weight: 600;', totalRow: true},
            {field: 'recommendBatchs', sort: true, title: 'Receipt Batch', style:'background-color: #dbf1e1;font-weight: 600;'},
            {field: 'storageDate', sort: true, title: 'Manufacturing Date', style:'background-color: #dbf1e1;font-weight: 600;'},
            {field: 'storageBatchnumber', sort: true, title: 'Batch', style:'background-color: #dbf1e1;font-weight: 600;'},
            {field: 'storageWeight', sort: true, title: 'Weight', totalRow: true},
            {field: 'storageVolume', sort: true, title: 'Volume', totalRow: true},
            {field: 'storagePrice', sort: true, title: 'Unit Price'},
            {field: 'storageMoney', sort: true, title: 'Amount', totalRow: true},
            {field: 'storageLargeclass', title: 'Category'},
            {field: 'storageGoodstype', title: 'Type', hide: true},
            {field: 'goodsUnit', title: 'Unit'},
            {field: 'storagePacking', title: 'Packaging'},
            {field: 'goodsSpecs', title: 'Specs'},
            {field: 'notes', title: 'Notes'},
        ]];
    };

    /**
     * 点击查询按钮
     */
    StorageOutDetailed.search = function () {
        var queryData = {};
        queryData['condition'] = $("#condition").val();
        queryData['storageOutStatus'] = $("#storageOutStatus").val();
        queryData['storageOutNumber'] = $("#storageOutNumber").val();
        queryData['storageBatchnumber'] = $("#storageBatchnumber").val();
        queryData['outStorehouseId'] = $("#outStorehouseId").val();
        queryData['startSingleTime'] = $("#startSingleTime").val();
        queryData['endSinglePutTime'] = $("#endSinglePutTime").val();
        queryData['startTime'] = $("#startTime").val();
        queryData['endTime'] = $("#endTime").val();
        table.reload(StorageOutDetailed.tableId, {
            where: queryData, page: {curr: 1},
             done:function () {
            }
        });
    };

    /**
     * 导出excel按钮
     */
    StorageOutDetailed.exportExcel = function () {
        var checkRows = table.checkStatus(StorageOutDetailed.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("Please select data to export");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + StorageOutDetailed.tableId,
        url: Feng.ctxPath + '/storageOutDetailed/chukujilu',
        page: true,
        limit: 120,
		limits:[60,120,240,360,480,1500,5000,10000,20000,80000],
        height: "full-60",
        toolbar: '#toolbarfrom',
        cellMinWidth: 100,
        totalRow: true ,//开启合计行
        cols: StorageOutDetailed.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        StorageOutDetailed.search();
    });

    // 单击行事件
    table.on('row(' + StorageOutDetailed.tableId + ')', function (obj) {
        var data = obj.data;
		$('div[lay-id="' + StorageOutDetailed.tableId + '"]').find(".layui-table-body tr ").attr({ "style": "background:#FFFFFF" });//Restore other rows
		$('div[lay-id="' + StorageOutDetailed.tableId + '"]').find(obj.tr.selector).attr({ "style": "background:#e6e6e6;" });//Change current row color
    });

    // 导出excel
    $('#btnExp').click(function () {
        StorageOutDetailed.exportExcel();
    });

    // 导出excel
    $('#btnExpBySpec').click(function () {
		window.location.href = Feng.ctxPath + '/storageOutDetailed/exportExcelBySpec?storageOutStatus='+$("#storageOutStatus").val()
		+"&storageOutNumber="+$("#storageOutNumber").val()+"&condition2="+$("#condition").val()
		+"&storageBatchnumber="+$("#storageBatchnumber").val()+"&outStorehouseId="+$("#outStorehouseId").val()
		+"&startSingleTime="+$("#startSingleTime").val()+"&endSinglePutTime="+$("#endSinglePutTime").val();
		+"&startTime="+$("#startTime").val()+"&endTime="+$("#endTime").val();
    });
});
